<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                name: 'zf'
            },
            methods: {
                handler(newValue, oldValue) {
                    console.log(newValue, oldValue)
                }
            },
            watch: {
                name: [
                    'handler',
                    {
                        handler: (newValue, oldValue) => {
                            console.log(newValue, oldValue)
                        },
                        immediate: true
                    }
                ]
            }
        });
        vm.$watch('name', (newValue, oldValue) => {
            console.log(newValue, oldValue,38)
        })
        vm.name = 100;
        vm.name = 200;
        // setTimeout(() => {
        //     vm.name = 'jw'
        // }, 1000);

        // 用户编写的watch 等价于 vm.$watch  -> 利用了watcher
        // 每个属性对应一个watcher，属性变化了可以触发watcher的更新
        // 用户watcher 是用户写的watcher ， 渲染watcher 渲染时使用的watcher
    </script>
</body>

</html>